import { Controller, Post, Body, Session, ParseIntPipe, UseGuards, UsePipes, ValidationPipe } from '@nestjs/common';
import { ContainerService } from './container.service';
import { DeleteDto, SqlQueryDto } from '@/common/type/app.dto';
import { CntrLeaseRateDto, CreateCntrDto, DeletePortCntrStatDto, DeletePortCntrStatsDto, GateOutDto, InPlanDto, InplanImportCntrDto, LeasePlanDto, OutPlanDto, PlanDto, QueryPlanCntrsDto, ReleaseFormDto, RentPlanDto, ReplyCntrFixDto } from './dto/create-container.dto';
import { UpdateCntrDto, UpdateInPlanDto, UpdateLeaseCntrDto, UpdateLeasePlanDto, UpdateOutPlanDto, UpdatePlanDto, UpdateRentPlanDto, UpdateTransPlanDto } from './dto/update-container.dto';
import { AuthGuard } from '@/common/guard/auth.guard';
import { BusiReportDto, LeaseFeeReportDto, LeaseReportDto } from '@/business/dto/create-business.dto';


@Controller('container')
@UseGuards(AuthGuard)
export class ContainerController {
    constructor(private readonly containerService: ContainerService) { }

    @Post('cntrinplancreate')
    async createincntrplan(@Body() dto: PlanDto) {
        if (dto instanceof InPlanDto) {
            return await this.containerService.createInPlan(dto, InPlanDto);
        } else {
            return await this.containerService.createInPlan(dto, PlanDto);
        }

    }
    @Post('cntrinplanupdate')
    async updateincntrplan(@Body() data: UpdateInPlanDto, @Session() session: Record<string, any>) {
        return await this.containerService.updateInPlan(data, session['user']['name']);
    }
    @Post('cntrinplandelete')
    async deleteincntrplan(@Body() dto: DeleteDto) {
        return await this.containerService.deleteInCntrPlan(dto);
    }
    @Post('cntrinplanquery')
    async getCntrPlan(@Body() query: SqlQueryDto) {
        return await this.containerService.queryCntrInPlan(query);
    }
    @Post('portcntrstatdelete')
    async deletePortCntrStat(@Body() dto: DeletePortCntrStatsDto) {
        return await this.containerService.delPortCntrStat(dto);
    }
    @Post('portcntrstatquery')
    async queryPortCntrStat(@Body() dto: SqlQueryDto) {
        return await this.containerService.queryPortCntrStat(dto);
    }
    @Post('exportcntrinplanquery')
    async exportGetCntrPlan(@Body() query: SqlQueryDto) {
        return await this.containerService.exportQueryCntrInPlan(query);
    }

    @Post('inplanaddprecntrs')
    async createinplanprecntrs(@Body() dto: InplanImportCntrDto) {
        return await this.containerService.InPlanAddPreCntrs(dto);
    }
    @Post('outplanaddprecntrs')
    async createoutplanprecntrs(@Body() dto: InplanImportCntrDto) {
        return await this.containerService.OutPlanAddPreCntrs(dto);
    }
    @Post('rentplanaddprecntrs')
    async createrentplanprecntrs(@Body() dto: InplanImportCntrDto) {
        return await this.containerService.RentPlanAddPreCntrs(dto);
    }
    @Post('transinplanaddprecntrs')
    async createtransinplanprecntrs(@Body() dto: InplanImportCntrDto) {
        return await this.containerService.TransInPlanAddPreCntrs(dto);
    }
    @Post('queryPlanPreCntrs')
    async queryPlanPreCntrs(@Body() dto: QueryPlanCntrsDto) {
        return await this.containerService.queryPlanPreCntr(dto);
    }

    @Post('deletePlanPreCntrs')
    async deletePlanPreCntrs(@Body() dto: DeleteDto) {
        return await this.containerService.deletePlanPreCntr(dto);
    }

    /* @Post('inplanimportcntr')
    async cntrinplanimportcntr(@Body() dto: InplanImportCntrDto, @Session() session: Record<string, any>) {
        return this.containerService.inplanImportCntr(dto, session['user']['name']);
    } */
    @Post('cntroutplancreate')
    async createoutcntrplan(@Body() dto: PlanDto) {
        if (dto.stat_cod === 'EOZYXC') {
            return await this.containerService.createOutPlan(dto, PlanDto);
        } else {
            return await this.containerService.createOutPlan(dto, OutPlanDto);
        }
    }
    /* @Post('cntroutplanupdate')
    async updateoutcntrplan(@Body() data: UpdateOutPlanDto, @Session() session: Record<string, any>) {
        return await this.containerService.updateOutPlan(data, session['user']['name']);
    } */
    @Post('cntroutplanupdate')
    async updateoutcntrplan(@Body() dto: UpdatePlanDto, @Session() session: Record<string, any>) {
        if (dto.stat_cod === 'EOZYXC') {
            return await this.containerService.updateOutPlan(dto as UpdateTransPlanDto, UpdateTransPlanDto, session['user']['name']);
        } else {
            return await this.containerService.updateOutPlan(dto as UpdateOutPlanDto, UpdateOutPlanDto, session['user']['name']);
        }
    }
    @Post('cntroutplandelete')
    async deleteoutcntrplan(@Body() dto: DeleteDto) {
        return await this.containerService.deleteOutCntrPlan(dto);
    }
    @Post('cntroutplanquery')
    async getCntrOutPlan(@Body() query: SqlQueryDto) {
        return await this.containerService.queryCntrOutPlan(query);
    }
    @Post('exportcntroutplanquery')
    async exportGetCntrOutPlan(@Body() query: SqlQueryDto) {
        return await this.containerService.exportQueryCntrOutPlan(query);
    }
    @Post('cntrleaseplancreate')
    async createleasecntrplan(@Body() dto: LeasePlanDto) {
        return await this.containerService.createLeasePlan(dto);
    }
    @Post('cntrrentplancreate')
    async createrentcntrplan(@Body() dto: RentPlanDto) {
        return await this.containerService.createRentPlan(dto);
    }
    @Post('cntrleaseplanupdate')
    async updateleasecntrplan(@Body() data: UpdateLeasePlanDto) {
        return await this.containerService.updateLeasePlan(data);
    }
    @Post('cntrrentplanupdate')
    async updaterentcntrplan(@Body() data: UpdateRentPlanDto) {
        return await this.containerService.updateRentPlan(data);
    }
    @Post('cntrleaseplandelete')
    async deleteleasecntrplan(@Body() dto: DeleteDto) {
        return await this.containerService.deleteLeaseCntrPlan(dto);
    }
    @Post('cntrrentplandelete')
    async deleterentcntrplan(@Body() dto: DeleteDto) {
        return await this.containerService.deleteRentCntrPlan(dto);
    }
    @Post('cntrleaseplanquery')
    async getCntrLeasePlan(@Body() query: SqlQueryDto) {
        return await this.containerService.queryCntrLeasePlan(query);
    }
    @Post('cntrrentplanquery')
    async getCntrRentPlan(@Body() query: SqlQueryDto) {
        return await this.containerService.queryCntrRentPlan(query);
    }
    @Post('exportcntrleaseplanquery')
    async exportGetCntrLeasePlan(@Body() query: SqlQueryDto) {
        return await this.containerService.exportQueryCntrLeasePlan(query);
    }
    /* @Post('cntrcreate')
    async createcntr(@Body() data: CreateCntrDto) {
        return await this.containerService.cntrCreateS(data);
    } */
    @Post('cntrupdate')
    async updatecntr(@Body() data: UpdateCntrDto) {
        return await this.containerService.updateCntr(data);
    }
    @Post('cntrdelete')
    async deletecntr(@Body() dto: DeleteDto) {
        return await this.containerService.deleteCntr(dto);
    }
    @Post('cntrquery')
    async getCntr(@Body() query: SqlQueryDto) {
        return await this.containerService.queryCntr(query);
    }
    @Post('exportcntrquery')
    async exportGetCntr(@Body() query: SqlQueryDto) {
        return await this.containerService.exportQueryCntr(query);
    }

    @Post('cntringate')
    async cntrIngate(@Body() dto: CreateCntrDto, @Session() session: Record<string, any>) {
        return await this.containerService.cntrIngate(dto, session['user']['name']);
    }
    @Post('gateout')
    async gateout(@Body() dto: GateOutDto) {
        return await this.containerService.gateout(dto);
    }
    @Post('replycntrfix')
    async replycntrfix(@Body() dto: ReplyCntrFixDto, @Session() session: Record<string, any>) {
        return await this.containerService.ReplyCntrFix(dto, session['user']['name']);
    }

    @Post('fixquotation')
    async fixquotation(@Body() query: SqlQueryDto) {
        return await this.containerService.queryFixQuotation(query);
    }



    /**
     * 盘存
     * @param query 
     * @returns 
     */
    @Post('inventoryquery')
    async getInventory(@Body() query: SqlQueryDto) {
        return await this.containerService.queryInventory(query);
    }
    @Post('exportinventoryquery')
    async exportGetInventory(@Body() query: SqlQueryDto) {
        return await this.containerService.exportQueryInventory(query);
    }
    @Post('inventorygroupquery')
    async getInventoryGroup(@Body() query: SqlQueryDto) {
        return await this.containerService.queryInventoryGroup(query);
    }
    /**
     * 
     * @returns 首页数据展示
     */
    @Post('cadisplay')
    async cadisplay() {
        return await this.containerService.caDisplay();
    }
    @Post('cntrleaseupdate')
    async updatecntrlease(@Body() data: UpdateLeaseCntrDto) {
        return await this.containerService.updateCntrLease(data);
    }

    @Post('cntrleaserateupdate')
    @UsePipes(new ValidationPipe({ whitelist: true }))
    async updatecntrleaserate(@Body() data: CntrLeaseRateDto) {
        return await this.containerService.updateCntrLeaseRate(data);
    }
    @Post('cntrleaserateclean')
    @UsePipes(new ValidationPipe({ whitelist: true }))
    async cleancntrleaserate(@Body() dto: DeleteDto) {
        return await this.containerService.cleanCntrLeaseRate(dto);
    }
    @Post('cntrleasequery')
    async getCntrLease(@Body() query: SqlQueryDto) {
        return await this.containerService.queryCntrLease(query);
    }
    @Post('cntrleasedetailquery')
    async getCntrLeaseDetail(@Body() query: SqlQueryDto) {
        return await this.containerService.queryCntrLeaseDetail(query);
    }
    @Post('cntrleasereport')
    async getCntrLeaseReport(@Body() query: LeaseReportDto) {
        return await this.containerService.queryCntrLeaseReport(query);
    }
    @Post('exportcntrleasequery')
    async exportGetCntrLease(@Body() query: SqlQueryDto) {
        return await this.containerService.exportQueryCntrLease(query);
    }

    @UsePipes(new ValidationPipe({ whitelist: true }))
    @Post('busireport')
    async busireport(@Body() dto: BusiReportDto) {
        return await this.containerService.busiEcharts(dto);
    }
    /**
     * 撤销出租箱返场
     * @param dto 
     * @returns 
     */
    @Post('cancelleasecntrback')
    async cancelleasecntrback(@Body() dto: DeleteDto) {
        return await this.containerService.cancelLeaseCntrBack(dto);
    }
    /**
     * 撤销出租箱出场
     * @param dto 
     * @returns 
     */
    @Post('cancelleasecntrout')
    async cancelleasecntrout(@Body() dto: DeleteDto) {
        return await this.containerService.cancelLeaseCntrOut(dto);
    }

    @Post('cancelcntrout')
    async cancelcntrout(@Body() dto: DeleteDto) {
        return await this.containerService.cancelCntrOut(dto);
    }

    @Post('cancelcntr')
    async cancelcntr(@Body() dto: DeleteDto) {
        return await this.containerService.cancelCntr(dto);
    }

    @Post('createreleaseformpdf')
    async createreleaseformpdf(@Body() dto: ReleaseFormDto, @Session() session: Record<string, any>) {
        return await this.containerService.createReleaseFormPDF(dto, session['user']['name']);
    }
    @Post('createinvoicepdf')
    async createinvoicepdf(@Body('invoice_id', ParseIntPipe) dto: number) {
        return await this.containerService.createInvoicePDF(dto);
    }

    @Post('releaseformquery')
    async releaseformquery(@Body() query: SqlQueryDto) {
        return await this.containerService.quueryReleaseForm(query);
    }

}
